package com.guide.dao.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import com.guide.dao.CommentsDao;
import com.guide.domain.CommentGuide;
import com.guide.domain.CommentGuideQuery;
import com.guide.domain.CommentTravel;
import com.guide.domain.CommentTravelQuery;
import com.guide.persistence.CommentGuideMapper;
import com.guide.persistence.CommentTravelMapper;
@Repository("commentsDao")
public class CommentsDaoImpl implements CommentsDao {
	private static final Logger logger = LoggerFactory
			.getLogger(CommentsDaoImpl.class);
	
	@Autowired
	private CommentGuideMapper commentGuideMapper;
	
	@Autowired
	private CommentTravelMapper commentTravelMapper;

	@Override
	public void insertCommentGuide(CommentGuide commentGuide) {
		// TODO Auto-generated method stub
		commentGuideMapper.insert(commentGuide);
	}

	@Override
	public void insertCommentTravel(CommentTravel commentTravel) {
		// TODO Auto-generated method stub
		commentTravelMapper.insert(commentTravel);
	}

	@Override
	public CommentGuide getCommentsByTeamIdAndGuideId(Long teammId, Long guideId) {
		CommentGuideQuery query = new CommentGuideQuery();
		query.createCriteria().andTeamIdEqualTo(teammId).andGuideIdEqualTo(guideId);
		List<CommentGuide> list = commentGuideMapper.selectByExampleWithBLOBs(query);
		if(!CollectionUtils.isEmpty(list)) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public CommentTravel getCommentsByTeamIdAndTravelorgId(Long teammId, Long guideId) {
		// TODO Auto-generated method stub
		CommentTravelQuery query = new CommentTravelQuery();
		query.createCriteria().andTeamIdEqualTo(teammId).andGuideIdEqualTo(guideId);
		List<CommentTravel> list = commentTravelMapper.selectByExampleWithBLOBs(query);
		if(!CollectionUtils.isEmpty(list)) {
			return list.get(0);
		}
		return null;
	}

	
	



}
